package parser;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import opennlp.tools.sentdetect.SentenceDetector;
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
import opennlp.tools.tokenize.Tokenizer;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;

public class OpenNLPPipeline extends ParserPipeline {
	private Tokenizer tok;
	private SentenceDetector sd;

	/**
	 * TODO add tokenizer and lemmatizer
	 */
	public OpenNLPPipeline(String dir) throws IOException {
		File smFile = new File(dir + "opennlp/en-sent.bin");
		FileInputStream smFis = new FileInputStream(smFile);
		SentenceModel sm = new SentenceModel(smFis);
		sd = new SentenceDetectorME(sm);
		smFis.close();

		File tmFile = new File(dir + "opennlp/en-token.bin");
		FileInputStream tmFis = new FileInputStream(tmFile);
		TokenizerModel tm = new TokenizerModel(tmFis);
		tok = new TokenizerME(tm);
		tmFis.close();
	}

	@Override
	public ParserAnnotation make(String document) {
		return new OpenNLPAnnotation(this, document);
	}

	Tokenizer getTokenizer() {
		return tok;
	}

	SentenceDetector getSentenceDetector() {
		return sd;
	}

}
